﻿using BattleFury.Lib;
using BattleFury.Lib.Bots;
using BattleFury.Lib.Players;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;

namespace BattleFury.Bots
{
    public class GenericBotV2 : Bot
    {
        private readonly Random _rnd = new Random();
        private int _distance = 0;

        public GenericBotV2(long Id)
            : base(Id)
        {
            Tint = new Color(_rnd.Next(0, 255), _rnd.Next(0, 255), _rnd.Next(0, 255), 255);
            Size = new Vector2(32f, 32f);
            Position = new Vector2(32f, 32f);
        }

        public override void LoadContent()
        {
            Texture = RenderEngine.Get().Content.Load<Texture2D>(".\\gfx\\Characters\\Character001");
            base.LoadContent();
        }

        public override void Update(GameTime gameTime)
        {
            switch (FacingDirection)
            {
                case FacingDirection.North:
                    Move(new Movement() { Direction = 0.0f, Velocity = 1.0f });
                    AdvanceKeyFrame();
                    _distance++;
                    if (_distance > 8)
                    {
                        _distance = 0;
                        FacingDirection = (FacingDirection)_rnd.Next(0, 3);
                    }
                    break;
                case FacingDirection.East:
                    Move(new Movement() { Direction = 90.0f, Velocity = 1.0f });
                    _distance++;
                    AdvanceKeyFrame();
                    if (_distance > 8)
                    {
                        _distance = 0;
                        FacingDirection = (FacingDirection)_rnd.Next(0, 3);
                    }
                    break;
                case FacingDirection.South:
                    Move(new Movement() { Direction = 180.0f, Velocity = 1.0f });
                    AdvanceKeyFrame();
                    _distance++;
                    if (_distance > 8)
                    {
                        _distance = 0;
                        FacingDirection = (FacingDirection)_rnd.Next(0, 3);
                    }
                    break;
                case FacingDirection.West:
                    Move(new Movement() { Direction = 270.0f, Velocity = 1.0f });
                    AdvanceKeyFrame();
                    _distance++;
                    if (_distance > 8)
                    {
                        _distance = 0;
                        FacingDirection = (FacingDirection)_rnd.Next(0, 3);
                    }
                    break;
            }
        }
    }
}